package com.it.listener;

import com.it.BeanFactory;
import com.it.ClassPathXmlApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class ServletContexInitListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("MyListener contextInitialized");
        String path = servletContextEvent.getServletContext().getInitParameter("contextConfigLocation");
        BeanFactory factory = new ClassPathXmlApplicationContext(path);
        servletContextEvent.getServletContext().setAttribute("factory", factory);

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("MyListener contextDestroyed");
    }
}
